package com.controller;

import com.model.User;
import com.service.UserService;
import com.tool.ResponseMessage;
import com.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 编写者：王懿宸
 * 编写时间：2019-5-29
 * 类模块描述：查询及相关增删改
 */
@RestController(value = "/User")
public class UserController {
    @Autowired
    private UserService userService;
@ApiOperation(value = "获取用户登录校验结果")
@CrossOrigin/*跨越访问*/
    @RequestMapping(value="/getUser",method = RequestMethod.PUT)
    public String setUname(@RequestBody User user){
    String returnStr="";
    if (user!=null){
        if (!user.getUname().isEmpty() &&user.getPasswd().isEmpty()){
            //对提供的数据进行校验
            returnStr=userService.getUser(user);
        }
    }
        return returnStr;
    }
    /*查询数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getUid")
    public User getUid(int uid){
        return userService.selectByPrimaryKey(uid);
    }
    /*查询数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getOne1")
    public User getOne1(int uid){
        return userService.selectByPrimaryKey(uid);
    }
    /*查询全部数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getAll1")
    public ResponseMessage getAll1(){
        System.out.println("调用角色全部信息");
        Map<String,List> map = new HashMap<>();
        map.put("list",userService.getAll1());
        return Result.success("200",map);
    }
    /*查询是否启用*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getUIsBegin")
    public List<User> getUIsBegin(){
        System.out.println("调用角色全部类型接口");
        List<User> listUser = userService.getUIsBegin();
        return listUser;
    }
    /*删除数据*/
    @CrossOrigin /*跨越访问*/
    @RequestMapping(value = "delUid",method = RequestMethod.GET)
    public int delUid(int uid){return userService.delUser(uid);}
    /*添加数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "addUid",method = RequestMethod.PUT)
    public int addUid(@RequestBody User usermodel){
        if (usermodel!=null){}
        else
            {}
        return userService.insertUser(usermodel);}
}
